package ControllerLayer;
import ModelLayer.*;

public class ForestOwnerCtr {
	private ForestContainer fContainer;
	private OwnerContainer oContainer;
	/**
	 * Constructor
	 * Initialize ForestContainer and OwnerContainer.
	 * Get instance of them.
	 * */
	public ForestOwnerCtr(){
		fContainer = ForestContainer.getInstance();
		oContainer = OwnerContainer.getInstance();
	}
	/**
	 * Create Owner and add Owner to Container
	 * @param String name, String address, String phoneNumber 
	 * */
	public void createOwner(String name, String address, String phoneNumber){
		Owner o = new Owner(name, address, phoneNumber);
		oContainer.addOwner(o);
	}
	/**
	 * Remove owner by name
	 * @param String name
	 * */
	public void removeOwner(String name){
		oContainer.removeOwner(name);
	}
	/**
	 * Find owner by name
	 * @param String name
	 * @return Owner or null
	 * */
	public Owner findOwnerByName(String name){
		return oContainer.findOwner(name);
	}
	/**
	 * Remove owner by phone
	 * @param String phone
	 * */
	public void removeOwnerByPhone(String phone){
		oContainer.removeOwnerByPhone(phone);
	}
	/**
	 * Find owner by phoneNumber
	 * @param String phoneNumber
	 * @return Owner or null
	 * */
	public Owner findOwnerByPhone(String phoneNumber){
		return oContainer.findOwnerByPhone(phoneNumber);
	}
	/**
	 * Create Forest and add it to forestContainer and add forest to Owner(Find owner by phoneNumber)
	 * @param String name, String location, float squareMeter, String NatureOfTrees, float Price, String phoneNumber
	 * */
	public void createForest(String name, String location, float squareMeter, String NatureOfTrees, float Price, String phoneNumber){
		Forest f = new Forest(name, location, squareMeter, NatureOfTrees, Price);
		fContainer.addForest(f);
		Owner o = findOwnerByPhone(phoneNumber);
		o.addForest(f);
	}
	/**
	 * create Forest without owner
	 * @param String name, String location, float squareMeter, String NatureOfTrees, float Price
	 * */
	public void createForestNoOwner(String name, String location, float squareMeter, String NatureOfTrees, float Price){
		Forest f = new Forest(name, location, squareMeter, NatureOfTrees, Price);
		fContainer.addForest(f);
	}
	/**
	 * Find Forest by name
	 * @param String name
	 * @return Forest forest
	 * */
	public Forest findForest(String name){
		return fContainer.findForest(name);
	}
	/**
	 * Remove forest
	 * @param String name
	 * */
	public void removeForest(String name){
		fContainer.removeForest(name);
	}
	/**
	 * Create tree and add to Forest you find by name
	 * @param String sort, String lifespan, float costPerSquareKilometer, String forestName
	 * */
	public void createTree(String sort, String lifespan, float cPSK, String forestName){
		Tree t = new Tree(sort, lifespan, cPSK);
		Forest f = findForest(forestName);
		f.addTree(t);
	}
	/**
	 * Find tree by its sort
	 * @param String forestName, String sort
	 * @return Tree tree or null
	 * */
	public Tree findTree(String forestName, String sort){
		Forest f = findForest(forestName);
		if(f.getTree(sort) != null){
			return f.getTree(sort);
		}else{
			return null;
		}
	}
	/**
	 * Remove tree by its sort
	 * @param String forestName, String sort
	 * */
	public void removeTree(String forestName, String sort){
		Forest f = findForest(forestName);
		f.removeTree(sort);
	}
}
